<?php

namespace Ignus\View\Node;

use Ignus\View\Node;
use Ignus\View\Node\Expression\Filter;
use Ignus\View\Compiler;
use Ignus\View\NodeInterface;

class SandboxedPrint extends PrintNode
{
    public function __construct(Expression $expr, $lineno, $tag = null)
    {
        parent::__construct($expr, $lineno, $tag);
    }

    public function compile(Compiler $compiler)
    {
        $compiler
            ->addDebugInfo($this)
            ->write('echo $this->env->getExtension(\'sandbox\')->ensureToStringAllowed(')
            ->subcompile($this->getNode('expr'))
            ->raw(");\n");
    }

    protected function removeNodeFilter(Node $node)
    {
        if ($node instanceof Filter) {
            return $this->removeNodeFilter($node->getNode('node'));
        }

        return $node;
    }
}
